<template>
  <div class="home-container">
    <comp-header class="bg-dark text-white">
      <template v-slot:logo>
        <h2
          class="text-white"
          style="
            background-image: url(https://qiniucssjs.gracg.com/logoimgs/img-horizontal-white.png);
          "
        >
          <router-link to="/"></router-link>
        </h2>
      </template>
      <template v-slot:logo-right>
        <a>
          <i class="fa fa-mobile icon"></i>
          <span>APP下载</span>
        </a>
        <div class="step">|</div>
        <a style="color: #adaeae">微博</a>
      </template>
      <template v-slot:search>
        <a @click="toSearch"><i class="fa fa-search icon"></i></a>
      </template>
      <template v-slot:text>
        <div class="logininfo" v-if="!userToken">
          <router-link to="/login/l1/gracg" class="login text-white"
            >登录</router-link
          >
          <div class="step" style="line-height: 53px">|</div>
          <router-link to="/login/l2/reg" class="register text-white"
            >注册</router-link
          >
        </div>
        <div v-if="userToken">
          <div class="avator" @click="showinfo">
            <img
              src="https://photo7n.gracg.com/314f100b74c6763c9c47039cbfe75d67.jpg!50x50"
              alt=""
              style="width: 30px; height: 30px"
              class="rounded-pill"
            />
          </div>
        </div>
      </template>
    </comp-header>
    <nav>
      <div class="w">
        <ul>
          <li>
            <router-link to="/feed">关注更新</router-link>
          </li>
          <li><router-link to="/works">作品</router-link></li>
          <li><router-link to="/best_more">推荐</router-link></li>
          <li><router-link to="/artist">作者</router-link></li>
          <li><a>活动比赛</a></li>
          <li>
            <div class="dropdown">
              <button>
                <span>插画外包合作平台</span>
                <i class="fa fa-angle-down" aria-hidden="true"></i>
              </button>
              <div class="dropdown-menu">
                <div>首页</div>
                <div>作品出售</div>
                <div>插画服务</div>
                <div>插画师列表</div>
                <div>SVIP权益</div>
              </div>
            </div>
          </li>
          <li>
            <div class="dropdown">
              <button>
                <span>王国绘画学院</span>
                <i class="fa fa-angle-down" aria-hidden="true"></i>
              </button>
              <div class="dropdown-menu">
                <div>直播课程</div>
                <div>绘画视频</div>
                <div>师资力量</div>
                <div>学员作业</div>
                <div><button>我要报名</button></div>
              </div>
            </div>
          </li>
        </ul>
      </div>
    </nav>
    <div style="background-color: #f8f9fa">
      <router-view />
    </div>
    <comp-footer></comp-footer>
    <div class="userinfo w position-relative">
      <ul
        class="box position-absolute rounded shadow-sm bg-white border"
        v-if="isShow"
      >
        <li class="acount"><p>User1344556744564575的主页</p></li>

        <li>
          <a href="#">个人中心</a>
          <a href="#">我的作品</a>
          <a href="#">资料修改</a>
        </li>
        <li>
          <a href="#">活动资料</a>
          <a href="#">赛事榜单</a>
        </li>
        <li class="logout">
          <button @click="logout">退出</button>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
import CompFooter from "../components/comp-footer.vue";
import CompHeader from "../components/comp-header.vue";
import CompMask from "../components/comp-mask.vue";
export default {
  name: "KdHome",
  components: {
    CompHeader,
    CompFooter,
    CompMask,
  },
  data() {
    return {
      userToken: "",
      isShow: false,
    };
  },
  computed: {
    ...mapState(["userModule"]),
  },
  methods: {
    toSearch() {
      this.$router.push({ path: "/search/index_new" });
    },
    showinfo() {
      this.isShow = !this.isShow;
    },
    logout() {
      localStorage.clear();
      this.userToken = null;
      this.isShow = false;
      this.$router.push("/login/l1/gracg");
    },
  },
  created() {
    this.userToken = localStorage.getItem("userToken");
  },
};
</script>

<style lang="less" scoped>
@import "../assets/reset";
nav {
  width: 100%;
  height: 50px;
  border-bottom: 1px solid #f0f0f0;
  padding-left: 0;
  margin-left: 0;
  ul {
    width: 100%;
    display: flex;
    align-items: center;
    padding: 0;
    margin: 0;

    li {
      height: 50px;
      margin: 0 15px;
      a {
        display: block;
        height: 50px;
        line-height: 50px;
        text-decoration: none;
        color: #000;
      }
      .router-link-active {
        border-bottom: 3px solid #cc9966;
      }
    }
    .dropdown {
      margin: 0 10px;
      height: 40px;
      line-height: 50px;
      position: relative;
      button {
        line-height: 40px;
      }
      .dropdown-menu {
        display: none;
        position: absolute;
        left: 0;
        top: 40px;
        border: 1px solid #000;
      }
    }
  }
}
.avator {
  width: 50px;
  height: 50px;
  line-height: 50px;
  cursor: pointer;
}
.userinfo {
  height: 0;
  .box {
    top: -2370px;
    right: 0;
    width: 220px;
    padding: 3px;
    z-index: 10000;
    li {
      padding: 15px 16px 0;
      font-size: 14px;
      border-bottom: 1px solid #ccc;
      &:last-child {
        border-bottom: 1px solid transparent;
      }

      p {
        font-size: 14px;
        font-weight: bold;
        color: #333;
      }
      a {
        display: block;
        font-size: 14px;
        padding-bottom: 10px;
        display: block;
        color: #333;
      }
      button {
        display: block;
        padding: 5px 10px;
        color: #333;
        cursor: pointer;
      }
    }
    .acount,
    .logout {
      padding-bottom: 15px;
    }
  }
}
</style>